#include "Arm.h"
#include "Visitor.h"
#include <math.h>
#define PI 3.14159265

void Arm::setAngleFirst (double a) 
{ 
	aFirst = a;
}
void Arm::setAngleSecond(double a) 
{ 
	aSecond = a;
}

void Arm::modifyAngleFirst (double a)
{
	setAngleFirst(a);
	NotifyAll();
}
void Arm::modifyAngleSecond(double a) 
{
	setAngleSecond(a);
	NotifyAll();
}
void Arm::Accept(Visitor *v)
{
	v->WhatToDo(this);
}
void Arm::calculate()
{

	int AB = getLinkFirst().getDistance();
	int BC = getLinkSecond().getDistance();
	double angle1 = getAngleFirst();
	double angle2 = getAngleSecond();
	Point C,B,A = getLinkFirst().getStart();
	double ax,ay,bx,by,cx,cy;

	ax = A.getX();
	ay = A.getY();
	bx =  AB*cos(PI * angle1 / 180.0 );
	by =  AB*sin(PI * angle1 / 180.0 );
	B.setX(bx);
	B.setY(by);

	getLinkFirst().setEnd(B);
	getLinkSecond().setStart(B);

	cx = bx + BC*sin(PI * (angle2 - 90 + angle1) / 180.0 );
	cy = by - BC*cos(PI * (angle2 - 90 + angle1) / 180.0 );
	
	C.setX(cx);
	C.setY(cy);

	getLinkFirst().setEnd(B);
	getLinkSecond().setEnd(C);

}
